package com.topica;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;

import com.topica.adapter.WeekAdapter;
import com.topica.object.WeekItem;
import com.viewpagerindicator.TabPageIndicator;

public class TopicaWeek extends FragmentActivity implements
		OnPageChangeListener {
	public static final String LIST_WEEK = "com.topica.TopicaDetailCourse.LIST_WEEK";
	public static final String INDEX = "com.topica.TopicaDetailCourse.INDEX";
	private ViewPager pager;
	private WeekAdapter adapter;
	private TabPageIndicator indicator;

	@SuppressWarnings("unchecked")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.acitivty_course_detail);
		ArrayList<WeekItem> data = (ArrayList<WeekItem>) getIntent().getExtras().getSerializable(LIST_WEEK);
		int index = getIntent().getExtras().getInt(INDEX) - 1;
		pager = (ViewPager) findViewById(R.id.pager);
		adapter = new WeekAdapter(getSupportFragmentManager(), data, index);
		pager.setAdapter(adapter);
		indicator = (TabPageIndicator) findViewById(R.id.indicator);
		indicator.setViewPager(pager);
		indicator.setCurrentItem(index);
		indicator.setOnPageChangeListener(this);
	}


	@Override
	public void onPageScrollStateChanged(int arg0) {
	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
	}

	@Override
	public void onPageSelected(int position) {
		 adapter.getWeekPager(position).onPagerChange();
	}
}
